from api.customer没有改造 import Customer
import requests
import pytest
from api.utils import Utils
import allure


class Test_customer:

    data = Utils.yaml_load('case/login_test.yaml')

    @classmethod
    def setup_class(cls):
        print('执行customer的初始化方法，创建customer对象')
        cls.c_obj = Customer()

    @allure.feature('未登陆测试')
    def test_api0101(self):
        param = {
            'action':'list_customer',
            'pagesize':'2',
            'pagenum':'2',
        }
        response = requests.get('http://127.0.0.1/api/mgr/customers',params=param)
        res = response.json()
        print(res)
        res_code = response.status_code
        assert  302 == res['ret']
        assert '未登录' == res['msg']
        assert '/mgr/sign.html' == res['redirect']

# def test_api0102():
#     # 用requests登陆
#     data = {
#         'username':'byhy',
#         'password':'88888888'
#     }
#     response = requests.post('http://127.0.0.1/api/mgr/signin',data=data)
#     print(response.headers)
#     login_cookie = response.headers['Set-Cookie']

#     # 登陆  
#     header = {
#         'cookie':login_cookie
#     }
#     param = {
#         'action':'list_customer',
#         'pagesize':'2',
#         'pagenum':'2',
#     }
#     response = requests.get('http://127.0.0.1/api/mgr/customers',params=param,headers=header)

#     # 检查一下发送的 需要启动chales 或者 
#     try:
#         requests.get('http://127.0.0.1:8082/get',params=param,headers=header,proxies={'http':'127.0.0.1:8888'})
#     except:
#         print('没有启动代理或者docker服务')

#     res = response.json()
#     res_code = response.status_code
#     assert res_code == 200
#     assert res['retlist'] != []
    @allure.feature('登陆展示客户1')
    def test_api0102(self):
        
        response = self.c_obj.list()
        res = response.json()
        res_code = response.status_code
        print(res)
        assert res_code == 200
        assert res['retlist'] != []

    @allure.feature('登陆展示客户2')
    @pytest.mark.parametrize('pagesize,pagenum',Utils.yaml_data(data,'test_medicine_list'))
    def test_api0103(self,pagesize,pagenum):
        response = self.c_obj.list(pagesize,pagenum)
        res = response.json()
        res_code = response.status_code
        print(res)
        assert res_code == 200
        assert res['retlist'] != []